<?php
/**
 *  玩家读取邮件
 */

class ReadEmail extends APIBase {
	public $tag = "ReadEmail";
	public $isLogin = true;
	
	public function before() {
		$this->initMysql();
		$this->inithttp();
		$this->initCacheRedis();
		return true;
	}
			
	public function logic() {
		$eid = $this->param['eid'];//邮件id
	    $uid = $this->uid;
		$emailinfo = $this->cache_redis->hGetAll('hemailbyuser:'.$uid.':'.$eid);
		$data = array();
		if(!empty($emailinfo)){
			$hmg = $this->cache_redis->hMget('hmg:'.$emailinfo['mid'],array('title','content','rid'));
			$this->cache_redis->hmset('hemailbyuser:'.$uid.':'.$eid,array('is_read'=>1));//改变邮件状态
			//判断邮件是否有附件
			if($hmg['rid']==''){
				//若没附件
				$data = array('title'=>$hmg['title'],'content'=>$hmg['content'],'reward'=>'');
			}else{
				//有附件
				$ridArr = explode(',',$hmg['rid']);
				$reward = array();
				for($i=0;$i<count($ridArr);$i++){
				    $hreward = $this->cache_redis->hMget('hreward:'.$ridArr[$i],array('propid','reward_quantity'));
					$hprop = $this->cache_redis->hMget('prop:'.$hreward['propid'],array('name'));
					$reward[] = array('name'=>$hprop['name'],'quantity'=>$hreward['reward_quantity']);
				}
				$data = array('id'=>$eid,'title'=>$hmg['title'],'content'=>$hmg['content'],'reward'=>$reward,'is_receive'=>$emailinfo['is_receive']);
			}
			$this->returnData($data);
		}else{
			$this->returnError(301,'无效参数！！');
		}
	}

	public function after() {
		$this->deinitDataRedis();
		$this->deinitMysql();
	}
}

?>
